package com.letoken.platform.repo.mall.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.letoken.platform.repo.app.res.user.QueryAmbassadorEquityRes;
import com.letoken.platform.repo.mall.po.AppMallAmbassador;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 推广大使 Mapper 接口
 * </p>
 *
 * @author author
 * @since 2023-06-05
 */
public interface AppMallAmbassadorMapper extends BaseMapper<AppMallAmbassador> {


    @Select("select 1 from app_mall_ambassador where user_id = #{userId} limit 1")
    Integer ambassadorExists(@Param("userId") Integer userId);

    @Select("select a.level,b.eco_value ," +
            "(select level_name from admin_mall_ambassador where level = a.level) as levelName " +
            "from app_mall_ambassador a inner join app_user_team b on a.user_id = b.user_id    where a.user_id = #{userId} and a.state = 0 ")
    QueryAmbassadorEquityRes queryAmbassadorInfo(@Param("userId") Integer userId);

    @Select("select count(1) from app_mall_ambassador where user_id = #{userId} and level >0")
    Integer getCountByUserAndLevel(@Param("userId") Integer userId);
}
